﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SurvivalSolitair
{
    public partial class Form1 : Form
    {
        const int BASE_TIMER_EASY = 60; // Currently in seconds
        const int BASE_TIMER_NORMAL = 45;
        const int BASE_TIMER_HARD = 30;
        const int BASE_TIMER_EXTREME = 20;

        public int time = 0;
        public bool gameRunning = false;


        public double MouseX = 0;
        public double MouseY = 0;


        public List<DropZone> myField = new List<DropZone>();
        
        public Form1()
        {
            InitializeComponent();
            //label1.Text = "Test";
            BuildField();

        }
        public void updateMouseMovement(object o, MouseEventArgs e)
        {
            MouseX = e.X;
            MouseY = e.Y;

        }
        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void gameToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void easyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Player clicked on start game on easy
            // Set base Time
            time = BASE_TIMER_EASY;
            lblTime.Text = Convert.ToString(time);
            CardDeck easyDeck = new CardDeck(this,50,50,myField);
            StartTimer();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (!CheckGameOver())
            {
                --time;
                UpdateTimer(time);
            }
            else
            {
                CreateGameOverScreen();
                StopTimer();
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void UpdateTimer(int _time)
        {
            lblTime.Text = Convert.ToString(_time);
        }

        private bool CheckGameOver()
        {
            if (time <= 0)
            {
                
                return true;
            }
            else
                return false;

        }

        private void StartTimer()
        {
            timer1.Start();
            gameRunning = true;
        }
        private void StopTimer()
        {
            timer1.Stop();
            gameRunning = false;
        }

        private void CreateGameOverScreen()
        {
            Form gameOverScreen = new Form();

            gameOverScreen.Width = 300;
            gameOverScreen.Height = 180;
            gameOverScreen.Visible = true;
            gameOverScreen.TopMost = true;
            gameOverScreen.Text = "Game Over";
            int score = 50;


            Label myLabel = new Label();
            myLabel.Width = 200;
            myLabel.Text = "You got a new highscore:" + score;
            myLabel.Visible = true;
            myLabel.Parent = gameOverScreen;
            myLabel.Location = new System.Drawing.Point(10, 10);

            Label PlayerName = new Label();
            PlayerName.Width = 200;
            PlayerName.Text = "Your name:";
            PlayerName.Visible = true;
            PlayerName.Parent = gameOverScreen;
            PlayerName.Location = new System.Drawing.Point(10, 50);

            TextBox inputName = new TextBox();
            inputName.Width = 200;
            inputName.Visible = true;
            inputName.Parent = gameOverScreen;
            inputName.Location = new System.Drawing.Point(10,75);

            Button Submit = new Button();
            Submit.Visible = true;
            Submit.Parent = gameOverScreen;
            Submit.Location = new System.Drawing.Point(10, 100);
            Submit.Text = "Submit";

            Button Cancel = new Button();
            Cancel.Visible = true;
            Cancel.Parent = gameOverScreen;
            Cancel.Location = new System.Drawing.Point(10 + Submit.Width + 10, 100);
            Cancel.Text = "Cancel";
        }

        private void quitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }






        private void normalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Player clicked on start game on normal
            // Set base Time
            time = BASE_TIMER_NORMAL;
            lblTime.Text = Convert.ToString(time);
            StartTimer();
        }

        private void hardToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Player clicked on start game on hard
            // Set base Time
            time = BASE_TIMER_HARD;
            lblTime.Text = Convert.ToString(time);
            StartTimer();
        }

        private void extremeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Player clicked on start game on EXTREME
            // Set base Time
            time = BASE_TIMER_EXTREME;
            lblTime.Text = Convert.ToString(time);
            StartTimer();
        }


        private void BuildField()
        {

            DropZone stack1 = new DropZone(this, 100, 200);
            Card.eventDropCard += stack1.onCardPlace;

            myField.Add(stack1);

        }
    }

    public class PlaceCardArgs
    {
        public List<DropZone> list;
        public PlaceCardArgs(List<DropZone> t)
        {
            list = t;

        }


    }

}
